


float4x4 g_projMatrix : PROJ;
float4x4 g_viewMatrix : VIEW;
float4x4 g_worldMatrix : WORLD;

float4 g_lightAmbient : LIGHTAMBIENT;
float4 g_lightDiffuse : LIGHTDIFFUSE;
float4 g_lightSpecular : LIGHTSPECULAR;
float3 g_lightPosition : LIGHTPOSITION;

float g_matPower : MATERIALPOWER;

texture g_texDiffuse : TEXTUREDIFFUSE;

sampler2D g_samDiffuse = 
sampler_state
{
	Texture = <g_texDiffuse>;
	MinFilter = Anisotropic;
	MagFilter = Anisotropic;
	MipFilter = Anisotropic;
	MaxAnisotropy = 16.0f;
};


struct VS_OUTPUT
{
	float4 position		: POSITION;
	float2 txt			: TEXCOORD0;
	float4 color		: COLOR;
};

struct PS_OUTPUT
{
	float4 color : COLOR0;
};

VS_OUTPUT MyVS(float4	pos		: POSITION,
			   float4   pos1	: POSITION1,
			   float4   normal	: NORMAL,
			   float2   txt		: TEXCOORD0,
			   uniform float4x4 worldViewMatrix,
			   uniform float4x4 worldViewProjMatrix)
{
	VS_OUTPUT output;
	float4 iPos = pos + pos1;
	output.position = mul (iPos, worldViewProjMatrix);

	float3 position = mul (iPos, worldViewMatrix).xyz;
	float3 norm = normalize(mul (float4(normal.xyz, 0.0), worldViewMatrix).xyz);
	float3 lightDir = normalize(mul(float4(g_lightPosition, 1.0), g_viewMatrix).xyz - position);

	float d = dot (norm, lightDir);

	output.color = float4 (d, d, d, 1.0);
	output.txt = txt;

	return output;
}


PS_OUTPUT MyPS(VS_OUTPUT input)
{
	PS_OUTPUT output;
	float4 diff = tex2D (g_samDiffuse, input.txt);
	if (diff.w < 0.5)
	{
		discard;
	}

	output.color = input.color * diff;

	return output;
}

technique TestTechnique
{
	pass P0
	{
		VertexShader = compile vs_2_0 MyVS(mul (g_worldMatrix, g_viewMatrix), mul(g_worldMatrix, mul (g_viewMatrix, g_projMatrix)));
		PixelShader  = compile ps_2_0 MyPS();
	}
}